package org.arch_learn.servlet_container.components.connector;

import org.arch_learn.servlet_container.pojo.Request;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Processor {
    public static Request buildRequest(InputStream inputStream) throws IOException {
        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }
        byte[] bytes = new byte[count];
        inputStream.read(bytes);

        String inputStr = new String(bytes);
        String[] arr = inputStr.split("\n\r\n");
        Arrays.stream(arr).forEach(v -> System.out.println(v));
        String firstLine = arr[0];
        String[] headArr = firstLine.split(" ");
        return new Request(inputStr, headArr[0], headArr[1]);
    }
}
